using D.Medicalcare.Domain.Entities;
using D.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace D.Application.Services
{
    public class RegistrationService
    {
        private readonly MedicalDbContext _context;

        public RegistrationService(MedicalDbContext context)
        {
            _context = context;
        }

        public async Task<List<RegistrationDto>> GetRealTimeRegistrationsAsync(string? patientName, string? phoneNumber, string? department, DateTime? registrationDate)
        {
            var query = _context.Registrations
                .Include(r => r.Department)
                .Include(r => r.Patient)
                .AsQueryable();

            return await query.Select(r => new RegistrationDto
            {
                PatientName = r.Patient.Name,
                PhoneNumber = r.Patient.PhoneNumber,
                DepartmentName = r.Department.Name,
                RegistrationFee = r.RegistrationFee,
                RegistrationTime = r.RegistrationTime
            }).ToListAsync();
        }
    }

    public class RegistrationDto
    {
        public string PatientName { get; set; }
        public string PhoneNumber { get; set; }
        public string DepartmentName { get; set; }
        public double RegistrationFee { get; set; }
        public DateTime RegistrationTime { get; set; }
    }
}
